const { BrowserWindow } = require('electron')
const path = require('path')
const { sendMainWin } = require('../window/mainWindow')

let win
const createControlWin = () => {
    win = new BrowserWindow({
        width: 1200,
        height: 800,
        webPreferences: {
            preload: path.join(__dirname, '../preload.js'),
            nodeIntegration: true,
            contextIsolation: false
        }
    })
    win.loadFile(path.join(__dirname, '../pages/renderer/index.html'))

    win.on('close', () => {
        sendMainWin('changeStatus', '', '1')
    })

    return win
}

// 向控制窗口发送数据
function sendControlWin(eventName, ...arg) {
    win.webContents.send(eventName, ...arg)
}

module.exports = {
    createControlWin,
    sendControlWin
}